package jjh;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;

public class MainScreen extends JFrame {

	private JPanel contentPane;
	ImageIcon icon;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainScreen frame = new MainScreen();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainScreen() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JLabel MainScreen = new JLabel("");
		contentPane.add(MainScreen, BorderLayout.CENTER);
		
		
		
		JLabel Timer = new JLabel("Timer");
		Timer.setHorizontalAlignment(SwingConstants.RIGHT);
		Timer.setText(getSysdate());
		Timer Time = new Timer(1000, new TimerListener(Timer));
		Time.start();
		contentPane.add(Timer, BorderLayout.SOUTH);
		
	}
	public static String getSysdate() {
		Date sysdate = new Date();
		String smt = "YYYY년 MM월 dd일 E요일 a hh:mm:ss";
		return new SimpleDateFormat(smt).format(sysdate);
	}
}

class TimerListener implements ActionListener {
	private JLabel Timer = null;
	public TimerListener(JLabel Timer) {
		this.Timer = Timer;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		Timer.setText(MainScreen.getSysdate());
	}
}